//
//  XLAccountSafePresenter.m
//  industry
//
//  Created by xl on 2020/12/9.
//  Copyright © 2020 Haier. All rights reserved.
//

#import "XLAccountSafePresenter.h"
#import "XLAccountSafePresenterProtocol.h"
#import "XLAccountSafeAdapter.h"
#import "XLAccountSafeViewProtocol.h"
#import "XLAccountSafeInteractorProtocol.h"

@interface XLAccountSafePresenter ()<XLAccountSafePresenterProtocol>

@end
@implementation XLAccountSafePresenter

- (void)dealloc {
    XLLog(@"XLAccountSafePresenter dealloc");
}

#pragma mark - XLAccountSafePresenterProtocol
- (NSArray *)getFunctions {
    return @[XLAccountSafeAdapterModifyPS,
             XLAccountSafeAdapterUnlockSettrings,
             XLAccountSafeAdapterClearData];
}

- (void)handleCellData:(id)data {
    if ([data isEqualToString: XLAccountSafeAdapterModifyPS]) {//修改密码
        XLSend(self.baseController.interactor, XLAccountSafeInteractorProtocol, gotoModifyPSVC);
    } else if ([data isEqualToString:XLAccountSafeAdapterClearData]) {//清空数据
        NSArray * array = [[NBServiceGet() appCenter] allAppIds];
        [array enumerateObjectsUsingBlock:^(NSString *  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            
            [[NBServiceGet() appCenter] clearAllAppInfo:obj];
        }];
        XLSend(self.baseController.cView, XLAccountSafeViewProtocol, reloadData);
        
        [XLToast showSuccessMessage:@"清空数据成功！"];
    } else if ([data isEqualToString:XLAccountSafeAdapterUnlockSettrings]) {//解锁设置
        XLSend(self.baseController.interactor, XLAccountSafeInteractorProtocol, gotoUnlockSettingVC);
    }
}

- (void)requestLoginOut {
    XLHttpRequest *request = [[XLHttpRequest alloc] init];
    XLSend(self.baseController.cView, XLAccountSafeViewProtocol, showLoadingAnimalWithTitle:@"退出登录中...");
    WEAKSELF
    [request requestWithMethod:XLHttpMedthTypeGET url:XLLoginOutUrl params:nil isExtraParams:NO successBlock:^(NSDictionary *dict) {
        STRONGSELF
        XLSend(strongSelf.baseController.cView, XLAccountSafeViewProtocol, hideLoadingAnimal);
        
        XLSend(strongSelf.baseController.interactor, XLAccountSafeInteractorProtocol, gotoLoginVC);
    } failBlock:^(XLServerRequestsStatus status, XLNetworkReachabilityStatus reachability, NSError *error, NSDictionary *dict) {
        STRONGSELF
        XLSend(strongSelf.baseController.cView, XLAccountSafeViewProtocol, hideLoadingAnimal);
    }];
}
@end
